package dao;

import model.InvoiceDetail;

import org.hibernate.SessionFactory;

public class InvoiceDetailDAO {
	private final SessionFactory sf = util.NewHibernateUtil.getSessionFactory();

	public boolean insertInvoiceDetail(InvoiceDetail ind) {
		try {
			sf.getCurrentSession().beginTransaction();
			sf.getCurrentSession().save(ind);
			sf.getCurrentSession().getTransaction().commit();
			return true;
		} catch (Exception em) {
			em.printStackTrace();
			sf.getCurrentSession().getTransaction().rollback();
			return false;
		}
	}
	public boolean deleteInvoiceDetail(InvoiceDetail ind) {
		try {
			sf.getCurrentSession().beginTransaction();
			sf.getCurrentSession().delete(ind);
			sf.getCurrentSession().getTransaction().commit();
			return true;
		} catch (Exception e2) {
			e2.printStackTrace();
			return false;
		}
	}
	public boolean updateInvoiceDetail(InvoiceDetail ind) {
		try {
			sf.getCurrentSession().beginTransaction();
			sf.getCurrentSession().saveOrUpdate(ind);
			sf.getCurrentSession().getTransaction().commit();
			return true;

		} catch (Exception e2) {
			e2.printStackTrace();
			return false;
		}
	}
	public InvoiceDetail searchInvoiceDetail(String id) {
		try {
			sf.getCurrentSession().beginTransaction();
			return (InvoiceDetail) sf.getCurrentSession().get(InvoiceDetail.class, id);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
